// LSL script generated: RLV-New.Addons.Posture.lslp Sun May  2 00:09:51 Westeuropäische Sommerzeit 2010
integer attachment = 1;
string cmdname;
key victim;
list gMenu = [];
list statesMenu = [0,0,0,0,0,0,0,0,0,0];
key ToucherID;
integer channel_dialog;
integer listen_id;
string msg = "Posture\nTrigger Animation";
list sideMenu = [" ","Back"," "];


string ANIM = "!p1";

makeMenu(){
    (gMenu = []);
    (gMenu += sideMenu);
    if ((llList2Integer(statesMenu,0) == 1)) (gMenu += "[x]Posture");
    else  (gMenu += "[ ]Posture");
    (channel_dialog = (-1 * ((integer)("0x" + llGetSubString(((string)llGetKey()),-5,-1)))));
    (listen_id = llListen(channel_dialog,"",NULL_KEY,""));
    llDialog(ToucherID,msg,gMenu,channel_dialog);
}

llLRP(integer element_new,integer placeinlist){
    (statesMenu = llListReplaceList(statesMenu,[element_new],placeinlist,placeinlist));
}

default {

    state_entry() {
    }

    
    run_time_permissions(integer perms) {
        if ((perms & 16)) {
            llSetTimerEvent(0.1);
        }
    }

    
    timer() {
        llStartAnimation(ANIM);
    }

    
    listen(integer channel,string name,key id,string message) {
        llListenRemove(listen_id);
        if ((message == "[x]Posture")) {
            llSetTimerEvent(0.0);
            llStopAnimation(ANIM);
            llLRP(0,0);
            makeMenu();
        }
        else  if ((message == "[ ]Posture")) {
            llRequestPermissions(llGetOwner(),16);
            llSetTimerEvent(0.1);
            llLRP(1,0);
            makeMenu();
        }
        else  if ((message == "Back")) {
            llMessageLinked(-4,1337,"DV_MAIN_MISC",ToucherID);
        }
    }

    
    link_message(integer sender,integer num,string str,key id) {
        if ((num == 1337)) {
            if ((str == llGetScriptName())) {
                llMessageLinked(-4,1338,llGetScriptName(),NULL_KEY);
                (ToucherID = id);
                makeMenu();
            }
        }
        if ((num == 1338)) {
            if ((str == "attachment")) (attachment = 1);
            else  if ((str == "device")) (attachment = 0);
            else  if ((str != llGetScriptName())) {
                llListenRemove(listen_id);
            }
        }
        if ((num == 1339)) {
            if ((str == "ON_REZ")) {
            }
            if ((str == "RESET")) {
                (statesMenu = [0,0,0,0,0,0,0,0,0,0]);
            }
        }
        if ((num == 1329)) {
            (victim = ((key)str));
            (cmdname = ((string)llGetKey()));
        }
    }
}
